// This terrain script will switch the terrain to the value of memory cell 3 when the
// flag in the first two memory cells is not 0. Otherwise, flips back.

beginterrainscript;

variables;
	short sdf1,sdf2,change_to;
	short original,change,x,y;
body;

beginstate 0;
	original=terrain_in_this_spot();
	sdf1=get_memory_cell(0);
	sdf2=get_memory_cell(1);
	change_to=get_memory_cell(2);
	x=my_loc_x();
	y=my_loc_y();
	set_script_mode(2);
	set_state_continue(2);	// has to check on load, or will delay when player enters town.
break;

beginstate 2;
	change=get_flag(sdf1,sdf2);
	if (change>0) set_terrain(x,y,change_to);
	else set_terrain(x,y,original);
break;